home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 205_01 / detab.c < prev    next >
Text File  |  1980-01-01  |  2KB  |  60 lines

  1. /*
  2. HEADER:                 CUG205.00;
  3. TITLE:                  DETAB for Microsoft;
  4. DATE:                   09/24/86;
  5. DESCRIPTION:
  6.   "Replaces TABs with the equivalent number of spaces.";
  7. KEYWORDS:               Software tools, Text filters;
  8. SYSTEM:                 MS-DOS;
  9. FILENAME:               DETAB.C;
  10. WARNINGS:
  11.   "The author claims copyrights and authorizes non-commercial use only.";
  12. AUTHORS:                 Michael M. Yokoyama;
  13. COMPILERS:              Microsoft;
  14. */
  15.  
  16. #include <stdio.h>
  17.  
  18. main(argc,argv)
  19. int argc;                       /* Number of command line words   */
  20. char *argv[];                   /* Pointers to command line words */
  21. {
  22.   FILE *in;                     /* File used for input            */
  23.   int c, column;
  24.  
  25.   if (argc != 2) {              /* Check if enough arguments      */
  26.     fprintf(stderr,"TAB removal utility\n");
  27.     fprintf(stderr,"Usage:      detab filename\n");
  28.     exit(1);
  29.   }
  30.  
  31.   if ((in = fopen(argv[1],"r")) == NULL) {
  32.     fprintf(stderr,"Can't open source file:     %s\n",argv[1]); 
  33.     exit(1);
  34.   }
  35.  
  36.   column = 1;
  37.  
  38.   while ((c = getc(in)) != EOF) {
  39.     switch(c) {
  40.     case '\t' : 
  41.       do {
  42.         putchar(' '); 
  43.         column++;
  44.       } 
  45.       while ((column % 8) != 1);
  46.       break;
  47.     case '\r':
  48.     case '\n': 
  49.       putchar(c); 
  50.       column = 1;
  51.       break;
  52.     default     :
  53.       putchar(c); 
  54.       column++;
  55.       break;
  56.     }
  57.   }
  58.   fclose(in);
  59. }
  60.